package com.lgk.mapper;

import com.lgk.domain.Role;
import com.lgk.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface RoleMapper {
    /**
     * 获取全部角色
     * @return
     */
    @Select("select *from role")
    List<Role> getAllRole() ;


    /**
     * 添加角色
     * @param role
     */
    @Insert("insert into role values(#{id},#{name},#{description})")
    void addRole(Role role);

    /**
     * id获取
     * @param id
     * @return
     */
    @Select("select *from role where id = #{id}")
    Role getById(Integer id);

    /**
     * 修改角色
     * @param role
     */
    @Update("update role set description = #{description} where id=#{id}")
    void updateRole(Role role);

    /**
     * 删除角色
     * @param id
     */
    @Delete("delete from role where id = #{id}")
    void deleteRole(Integer id);

    /**
     * 按角色名字模糊查询
     * @return
     */
    @Select("select *from role where name like concat('%',#{name},'%') ")
    List<Role> getByNameAllRole(String name);

    /**
     * 根据用户id获取用户角色
     * @param uId
     * @return
     */
    @Select("select * from ur ur, role r where ur.rId = r.id and ur.uId= #{uId}")
    List<Role> getByUId(Integer uId);
}
